<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>查看学员试卷</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=0.5, user-scalable=no" name="viewport"/>
    <style>
        body {
            margin: 0;
            padding: 0;
            background: #f1f1f1;
            font-family: Helvetica, Tahoma, Arial, 'PingFang SC', 'Hiragino Sans GB', 'Heiti SC', STXihei, 'Microsoft YaHei', SimHei;
        }

        .public {
            background: #fff;
            max-width: 700px;
            padding: 80px 144px;
        }

        .title {
            text-align: center;
            font-size: 20px;
        }

        .subjet {
            text-align: center;
            font-size: 18px;

        }

        .user_info {
            margin-top: 40px
        }

        .yihan {
            font-size: 16px;
            margin-bottom: 8px;
        }

        .yihan .exam_url {
            width: 100px;
            height: 140px;
        }

        .topic {
            margin-top: 40px
        }

        .topic_title {
            font-size: 16px;
            margin: 20px 0;
        }

        .topic_item {
            margin-bottom: 6px
        }

        .Confirm_Print {
            width: 200px;
            text-align: center;
            cursor: pointer;
            color: #fff;
            position: fixed;
            top: 20px;
            right: 20px;
        }

        .btns {
            text-align: right;
            width: 700px;
            margin: 2rem auto;
        }

        .btns > a {
            border: 1px solid #016DD9;
            background-color: #016DD9;
            color: #FFFFFF;
            margin-left: 25px;
            padding: 8px 16px;
            border-radius: 4px;
            cursor: pointer;
            display: inline-block;
        }

        .btns > a > img {
            width: 28px;
            height: 28px;
            vertical-align: middle;
            margin-right: 4px;
            margin-top: -4px;
        }

        .btns > a:first-child {
            background-color: #FFFFFF;
            color: #016DD9;
            font-weight: 600;
        }

        .qianming {
            height: 200px;
            transform: rotate(90deg);
            -ms-transform: rotate(270deg);
            -moz-transform: rotate(270deg);
            -webkit-transform: rotate(270deg);
            -o-transform: rotate(270deg);
            margin-left: 80px
        }

    </style>
</head>
<body>
<div class="Confirm_Print btns">
    <a href="javascript:;" id="doPrint"><img src="./assets/img/print.png"/>在线打印</a>
    <a style="border: 1px solid #016DD9;
    background-color: #016DD9;
    color: #FFFFFF;
    margin-left: 25px;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    display: inline-block;" href="javascript:;" id="download"><img
            src="./assets/img/download.png"/>下载试卷</a>
</div>
<div id="c">
    <div id="content" class="public">
        <div class="title">
            {:date('Y')}年在线学习系统
        </div>
        <div class="subjet">{$paper.paper_titile} 在线测评考试试卷</div>
        <div class="user_info">
            <div class="yihan">
                <div class="layui-row">
                    <div class="layui-col-xs9 layui-col-sm9 layui-col-md9">
                        <div>姓名：{$paper.user['full_name']}</div>
                        <div style="border-bottom: 1px solid #777;margin: 10px 0"></div>
                        身份证号码：{$paper.user['idnumber']}<br>
                        测评工种：{$paper.application['job']['subject_name']}
                        [{$paper.application['subject_level']['level_name']}]<br>
                        手机号码：{$paper.phone?$paper.phone:'-'}<br>
                        测评分数：{$paper.exam_score}分<br>
                    </div>
                    <div class="layui-col-xs3 layui-col-sm3 layui-col-md3" style="text-align: right">
                        <img class="exam_url" src="{$paper.application['face_file']['external_url']}">
                    </div>

                </div>
            </div>
            <div class="yihan">
                <div class="layui-row">
                    <div class="layui-col-md6">
                    </div>
                    <div class="layui-col-md6">
                    </div>

                </div>
            </div>
        </div>
        <div class="topic">
            <div class="topic_title">一、单选题 （每题2分）</div>
            {foreach $t1 as $k=>$v}
            <div class="topic_item">{$k+1}. {$v.title}
                {foreach $v.qt_item as $c}
                <div>{$c.value}</div>
                {/foreach}
                <div style="color: red">
                    选择:{if$v.choose_answer}{$v.choose_answer}{else}未做题{/if} 回答{if$v.is_right==1}正确{else}错误{/if}
                </div>
            </div>
            {/foreach}
            <div class="topic_title">二、多选题 （每题2分）</div>
            {foreach $t2 as $k=>$v}
            <div class="topic_item">{$k+1}. {$v.title}
                {foreach $v.qt_item as $c}
                <div>{$c.value}</div>
                {/foreach}
                <div style="color: red">
                    选择:{if$v.choose_answer}{$v.choose_answer}{else}未做题{/if} 回答{if$v.is_right==1}正确{else}错误{/if}
                </div>
            </div>
            {/foreach}
            <div class="topic_title">三、判断题 （每题2分）</div>
            {foreach $t3 as $k=>$v}
            <div class="topic_item">{$k+1}. {$v.title}
                {foreach $v.qt_item as $c}
                <div>{$c.item}.{$c.value}</div>
                {/foreach}
                <div style="color: red">
                    选择:{if$v.choose_answer}{$v.choose_answer}{else}未做题{/if} 回答{if$v.is_right==1}正确{else}错误{/if}
                </div>
            </div>
            {/foreach}
        </div>
        <div style="font-size: 16px">
            <div style="margin-top: 40px">本人承诺：本试卷由本人亲自参加考试，并取得的成绩。</div>
            <div>考试时间：{$paper.create_time}</div>
            <div>考生签名：
                {if$paper.examsign_file}
                <img src="{$paper.examsign_file['external_url']}" class="qianming">
                {else}
                无签名
                {/if}
            </div>
        </div>
    </div>
</div>
</body>
</html>
<!-- 图片生成 -->
<script src="./assets/js/jquery.min.js"></script>
<script src="./assets/js/html2canvas.js"></script>
<script>
    function scrollToTop() {
        window.scrollTo({
            top: 0,
            left: 0,
        });
    }
    $(function () {
        $("#doPrint").click(() => {
            window.document.body.innerHTML = $("#c").html()
            window.print()
            location.reload()
        })
        $("#download").click(() => {
            scrollToTop()
            setTimeout(() => {
                html2canvas(document.querySelector("#content"), {scale: 2}).then(canvas => {
                    const imgUrl = canvas.toDataURL("image/png");
                    var numeral = '{$paper.paper_titile}';
                    // 如果浏览器支持msSaveOrOpenBlob方法（也就是使用IE浏览器的时候），那么调用该方法去下载图片
                    if (window.navigator.msSaveOrOpenBlob) {
                        var bstr = atob(imgUrl.split(',')[1]);
                        var n = bstr.length;
                        var u8arr = new Uint8Array(n);
                        while (n--) {
                            u8arr[n] = bstr.charCodeAt(n);
                        }
                        var blob = new Blob([u8arr]);
                        window.navigator.msSaveOrOpenBlob(blob, numeral + '.' + 'png');
                    } else {
                        // 这里就按照chrome等新版浏览器来处理
                        const a = document.createElement('a');
                        a.href = imgUrl;
                        a.setAttribute('download', numeral);
                        // 触发点击
                        document.body.appendChild(a);
                        a.click();
                        // 然后移除
                        document.body.removeChild(a);
                    }
                });
            }, 1000)

        })
    })
</script>
